import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import { checkBusinessLevelSelect, checkProductList } from '../../actions/couponManage/createCoupon'
import { getBusinessLevelSelect, getProductList, getProductListTotal } from '../../reducers/CouponManage/createCoupon'
import CreateCoupon from '../../views/CouponManage/CreateCoupon/index'
import { bindActionCreators } from 'redux'

const CreateCouponContainer = ({
        businessLevelSelect,
        productList,
        productListTotal,
        checkBusinessLevelSelect,
        checkProductList,
    }) => {
    return (
    <CreateCoupon 
        businessLevelSelect={businessLevelSelect}
        productList={productList}
        productListTotal={productListTotal}
        onCheckProduct={(data)=> checkProductList(data)}
        onCheckBusinessLevelSelect={(data)=> checkBusinessLevelSelect(data)} 
    />)}

CreateCouponContainer.propTypes = {
    businessLevelSelect: PropTypes.array,
    productList: PropTypes.array,
    productListTotal: PropTypes.number,
    checkBusinessLevelSelect: PropTypes.func,
    checkProductList: PropTypes.func,
}

const mapStateToProps  = (state) =>({
    businessLevelSelect:getBusinessLevelSelect(state.createCoupon),
    productList:getProductList(state.createCoupon),
    productListTotal:getProductListTotal(state.createCoupon),
})

const mapDispatchToProps = (dispatch) => ({
    checkProductList: bindActionCreators(checkProductList,dispatch),
    checkBusinessLevelSelect: bindActionCreators(checkBusinessLevelSelect,dispatch),
})

export default withRouter(connect(
    mapStateToProps,
    mapDispatchToProps
  )(CreateCouponContainer))